package org.strieber.gbjava;

import java.awt.Component;

public class GBZ80 {

	// 8-bit registers
	int a, b, c, d, e, f;
	// 16-bit registers
	public int sp, pc, hl;
	
	// # of instructions that have been executed
	// since the last reset
	int instructionCount = 0;
	
	boolean interruptsEnabled = false;
	
	// used to implement the IE delay slot (research this)
	int ieDelay = -1;
	boolean timaEnabled = false;
	int intructionsPerTima = 6000;
	
	// TRUE when the CPU is currently handling an interrupt
	boolean inInterrupt = false;
	
	// The breakpoint flag
	boolean breakPointEnable = false;
	
	// Constants for the flag register
	final short F_ZERO = 		0x80;
	// Subtract/Negative flag
	final short F_SUBTRACT = 	0x40;
	// Half carry flag
	final short F_HALFCARRY = 	0x20;
	// Carry flag
	final short F_CARRY = 		0x10;
	
	final short INSTRUCTIONS_PER_VBLANK = 9000;
	
	// used to set the speed of the emulator
	// this controls how many instructions are executed
	// per horizontal line scanned (* 154 = instructions per frame)
	final short BASE_INSTRUCTIONS_PER_HBLANK = 	60;
	short INSTRUCTIONS_PER_HBLANK = BASE_INSTRUCTIONS_PER_HBLANK;
	
	// used to set the speed of DIV increments
	final short BASE_INSTRUCTIONS_PER_DIV = 	33;
	short INSTRUCTIONS_PER_DIV = BASE_INSTRUCTIONS_PER_DIV;
	
	// vertical blank interrupt
	public final short INT_VBLANK =	0x01;
	// LCD coincidence interrupt
	public final short INT_LCDC =	0x02;
	// TIMA interrupt
	public final short INT_TIMA =	0x04;
	// Serial interrupt
	public final short INT_SER	=	0x08;
	// P10 - P13 (Joypad) interrupt
	public final short INT_P10 =	0x10;
	
	String[] registerNames =
		{"B", "C", "D", "E", "H", "L", "(HL)", "A"};
	String[] aluOperations =
		{"ADD", "ADC", "SUB", "SBC", "AND", "XOR", "OR", "CP"};
	String[] shiftOperations =
		{"RLC", "RRC", "RL", "RR", "SLA", "SRA", "SWAP", "SRL"};
	
	// 8kb of main system RAM at 0xC000 in address space
	// 32kb for GBC
	byte[] mainRam = new byte[0x8000];
	
	// 256 bytes at top of RAM are used mainly for registers
	byte[] oam = new byte[0x100];
	
	Cartridge cartridge;
	GraphicsChip graphicsChip;
	SoundChip soundChip;
	GameLink gameLink;
	IoHandler ioHandler;
	Component applet;
	boolean terminate;
	boolean running = false;
	
	boolean gbcFeatures = true;
	boolean allowGbcFeatuers = true;
	int gbcRamBank = 1;
	
	// Create a CPU emulator with supplied cartridge and game link objects
	public GBZ80(Cartridge cartridge, GameLink gameLink, Component applet) {
		this.cartridge = cartridge;
		this.gameLink = gameLink;
		//if (gameLink != null)
		
	}
}